package com.ssy.lingxi.contract.repository;

import com.ssy.lingxi.contract.entity.ContractExecuteInfoDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 合同执行情况
 * @author 伍将
 * @date 2021/3/9
 * @version 2.0.0
 */
public interface ContractExecuteInfoRepository extends JpaRepository<ContractExecuteInfoDO, Long>, JpaSpecificationExecutor<ContractExecuteInfoDO> {

    /**
     * 查询合同执行情况
     * @author 伍将
     * @date 2021/3/9
     * @param contractId: 合同id
     * @param orderId: 单据id
     * @param orderType: 单据类型
     * @param isHasTax: 是否含税
     * @param taxRate: 税率
     * @return 合同执行请款
     **/
    @Query(value = "select * from con_contract_execute_info " +
            "where contract_id =:contractId and order_id =:orderId " +
            "and order_type =:orderType and is_Has_Tax =:isHasTax and tax_rate =:taxRate " +
            "limit 1", nativeQuery = true)
    ContractExecuteInfoDO findData(Long contractId, Long orderId, Integer orderType, Integer isHasTax, Double taxRate);

    /**
     * 根据id集合查询合同执行请款
     * @author 伍将
     * @date 2021/3/10
     * @param idList: id集合
     * @return 合同执行请款
     **/
    List<ContractExecuteInfoDO> findAllByIdIn(List<Long> idList);

    /**
     * 根据id集合查询合同执行请款
     * @author ds
     * @date 2021/4/22
     * @param contractId: 合同id
     * @return 合同执行请款
     **/
    List<ContractExecuteInfoDO> findAllByContractId(Long contractId);
}
